package com.group.model;

import java.util.*;

/**
 * @author lenovo
 */
public class Student {
    private String id, name, gender, birth;
    private Map<String, Double> scores = new HashMap<>();

    public Student(){
        //
    }
    public Student(String id, String name, String gender, String birth) {
        this.id = id; this.name = name; this.gender = gender; this.birth = birth;
        scores.put("Math",0.0);scores.put("Java",0.0);scores.put("PE",0.0);
    }
    public void addScore(String course, double score) { scores.put(course, score); }
    public double getAverage() {
        return scores.values().stream().mapToDouble(Double::doubleValue).average().orElse(0);
    }
    public String getId() { return id; }
    public String getName() { return name; }

    public void setId(String id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getBirth() {
        return birth;
    }

    public void setBirth(String birth) {
        this.birth = birth;
    }

    public void setScores(Map<String, Double> scores) {
        this.scores = scores;
    }

    public Map<String, Double> getScores() { return scores; }

    public String toText() {
        StringBuilder sb = new StringBuilder(id + "\t" + name + "\t" + gender + "\t" + birth);
        for (Map.Entry<String, Double> e : scores.entrySet()) {
            sb.append("\t").append(e.getKey()).append(":").append(e.getValue());
        }
        return sb.toString();
    }
}
